package com.groupfifteen.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.groupfifteen.dao.SysAdminDao;
import com.groupfifteen.entity.SysAdminEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysAdminService;
import com.groupfifteen.vo.SysAdminVo;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("sysAdminService")
public class SysAdminServiceImpl extends ServiceImpl<SysAdminDao, SysAdminEntity>
        implements SysAdminService {
    @Override
    public Integer AddSysAdmin(SysAdminEntity sysAdminEntity) {

        return baseMapper.insert(sysAdminEntity);
    }
    @Override
    public Integer DeleteSysAdmin(Integer adminId) {

        return baseMapper.deleteById(adminId);
    }

    @Override
    public SysAdminEntity GetSysAdmin(Integer adminId) {
        return baseMapper.selectById(adminId);
    }

    @Override
    public  Integer UpdateSysAdmin(SysAdminEntity sysAdminEntity){

        return baseMapper.updateById(sysAdminEntity);
    }

    @Override
    public IPage<SysAdminEntity> Query(SysAdminEntity sysAdminEntity, int pageNo, int pageSize) {

        LambdaQueryWrapper<SysAdminEntity> query = Wrappers.lambdaQuery();
        query.eq(sysAdminEntity.getAdminId() != null, SysAdminEntity::getAdminId, sysAdminEntity.getAdminId());

        if( pageNo == 0 )
        {
            pageNo = 1;
        }
        if( pageSize == 0 ){
            pageSize = 10;
        }

     IPage<SysAdminEntity> page = Page.of(pageNo, pageSize);

        return baseMapper.selectPage(page, query);
    }

    @Override
    public IPage<SysAdminEntity> Query(SysAdminVo sysAdminVo) {
//        LambdaQueryWrapper<SysUserEntity> query = Wrappers.lambdaQuery();
//        query.eq(sysUserVo.getId() != null, SysUserEntity::getId, sysUserVo.getId());
//
//
//        long pageNo = 1 , pageSize = 10;
//        IPage<SysUserEntity> page = Page.of(pageNo, pageSize);
//
//        return null;
        LambdaQueryWrapper<SysAdminEntity> query = Wrappers.lambdaQuery();
        query.eq(sysAdminVo.getAdminId() != null, SysAdminEntity::getAdminId, sysAdminVo.getAdminId())
                .eq(sysAdminVo.getAdminName() != null, SysAdminEntity::getAdminName, sysAdminVo.getAdminName())
                .eq(sysAdminVo.getPwd() != null, SysAdminEntity::getPwd, sysAdminVo.getPwd());

        int currentPage = sysAdminVo.getCurrentPage();
        int pageSize = sysAdminVo.getPageSize();
        IPage<SysAdminEntity> page = new Page<>(currentPage, pageSize);

        return baseMapper.selectPage(page, query);
    }


}